<?php
/**
 *	Copyright (c) TeamFlamingo And gray 2004-2009
 *	www.me-live.com.cn / www.i-gray.cn
 *
 *	[ WARNING ]
 *		This is NOT a freeware!
 *		You MUST get author's authorization before using it!
 *	[ WARNING ]
 *
 *	Name : ubb2html.lib.php / Development Code Evolve
 *	Created / Modify : 2010-6-10 / --
 */

	if( !defined( 'IN_TEAME' ) )
	{
		exit( 'Access Denied' );
	}

	class	ubb2html
	{
		Protected	$string;

		public	function	__construct()
		{
			$this->string	=	'';
		}

		public	function	parse( $string )
		{
			$this->string	=	$string;
			//	[CH]	粗体、斜体、下滑线
			$this->string	=	preg_replace( "/\[b\](.*?)\[\/b\]/is", '<b>$1</b>', $this->string );
			$this->string	=	preg_replace( "/\[i\](.*?)\[\/i\]/is", '<i>$1</i>', $this->string );
			$this->string	=	preg_replace( "/\[u\](.*?)\[\/u\]/is", '<u>$1</u>', $this->string );

			//	[CH]	高亮代码
			$this->string	=preg_replace( "/\[code\stype=(\w+)\]\<pre\>(.*?)\<\/pre\>\[\/code\]/is", $this->makeCode( '$2', '$1' ), $this->string );
			//	[CH]	隐藏文字
			$this->string	=preg_replace( "/\[hide\](.*?)\[\/hide\]/is", $this->makeHide( '$1' ), $this->string );

			return	$this->string;
		}

		private	function	makeCode( $string, $type )
		{
			//return	'<div class="quteDiv"><p class="qute_p_title">引用<img src="'.$this->site.'/u/images/qute.gif" style="margin-top:0px" align="absmiddle"></p><p class="qute_p_content">'.$string.'</p></div>';
			return	'<div id="meHighlight"><textarea id="meSourceCode" class="' . $type . '">' . $string . '</textarea></div>';
		}

		private	function	makeHide( $string )
		{
			//if( isset( $_SESSION['auth'] ) && $_SESSION['auth'] == TRUE )
			//	return	$string;
		//	else
			//	return	'<div style="border:1px solid red;margin-top:5px;background-color:#f9e600;color:#333"><p style="border:1px solid #ffc"><img src="'.$this->site.'/u/images/light.gif" align="absmiddle" />
			//	出于某种原因，作者隐藏了此部分文字，请登陆以获得足够的浏览权限!</p></div>';
		}
	}
?>